package com.hkws.hkws.API;

import com.alibaba.fastjson.JSON;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.hkws.hkws.pojo.*;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class DoorResouceApi {
    /**
     * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
     */
    static {
        ArtemisConfig.host = "10.140.161.12:443";
        ArtemisConfig.appKey = "29544061"; // 秘钥appkey
        ArtemisConfig.appSecret = "N1Ims5vjYUTQIGdItUjc";
    }
    /**
     * STEP2：设置OpenAPI接口的上下文
     */
    private static final String ARTEMIS_PATH = "/artemis";

    //查询门禁点列表v2
    public  String searchDoorDot(SearchRequest searchRequest ){
        String searchDataApi = ARTEMIS_PATH +"/api/resource/v2/door/search";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",searchDataApi);
            }
        };
        String body= JSON.toJSONString(searchRequest);
        String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }

    //查询门禁设备列表v2
    public  String searchDevice(SearchRequest searchRequest ){
        String searchDataApi = ARTEMIS_PATH +"/api/resource/v2/acsDevice/search";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",searchDataApi);
            }
        };
        String body=JSON.toJSONString(searchRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }

    //查询门禁设备列表
    public  String acsDeviceList(AcsDeviceListRequest acsDeviceListRequest ){
        String acsDeviceListDataApi = ARTEMIS_PATH +"/api/resource/v1/acsDevice/advance/acsDeviceList";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",acsDeviceListDataApi);
            }
        };
        String body=JSON.toJSONString(acsDeviceListRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }
    //获取单个门禁设备信息
    public  String acsDeviceInfo(AcsDeviceInfoRequest acsDeviceInfoRequest ){
        String acsDeviceInfoDataApi = ARTEMIS_PATH +"/api/resource/v1/acsDevice/indexCode/acsDeviceInfo";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",acsDeviceInfoDataApi);
            }
        };
        String body=JSON.toJSONString(acsDeviceInfoRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }

    //查询门禁点列表
    public  String acsDoorList(AcsDoorListRequest acsDoorListRequest ){
        String acsDoorListDataApi = ARTEMIS_PATH +"/api/resource/v1/acsDoor/advance/acsDoorList";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",acsDoorListDataApi);
            }
        };
        String body=JSON.toJSONString(acsDoorListRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }

    //获取单个门禁点信息
    public  String acsDoorInfo(AcsDoorInfoRequest acsDoorInfoRequest ){
        String acsDoorInfoDataApi = ARTEMIS_PATH +"/api/resource/v1/acsDoor/indexCode/acsDoorInfo";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",acsDoorInfoDataApi);
            }
        };
        String body=JSON.toJSONString(acsDoorInfoRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }


    //增量获取门禁读卡器数据
    public  String timeRange(TimeRangeRequest timeRangeRequest ){
        String timeRangeDataApi = ARTEMIS_PATH +"/api/resource/v1/reader/timeRange";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",timeRangeDataApi);
            }
        };
        String body=JSON.toJSONString(timeRangeRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }

    //查询门禁读卡器列表
    public  String search(SearchRequest searchRequest ){
        String searchDataApi = ARTEMIS_PATH +"/api/resource/v1/reader/search";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",searchDataApi);
            }
        };
        String body=JSON.toJSONString(searchRequest);
        String result =ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        return result;
    }
}
